# -*- coding: utf-8 -*-

def merge(li, low, mid, high):
    i = low
    j = mid + 1
    ltmp = []

    while i <= mid and j <= high:
        if li[i] < li[j]:
            ltmp.append(li[i])
            i += 1
        else:
            ltmp.append(li[j])
            j += 1

    while i <= mid:
        ltmp.append(li[i])
        i += 1
    while j <= high:
        ltmp.append(li[j])
        j += 1
    # print(low)
    li[low:high + 1] = ltmp
    return li


# print(merge([1, 5, 6, 7, 2, 4, 9], 0, 3, 6))
def merge_sort(li, low, high):
    if low < high:
        mid = (low + high) // 2
        merge_sort(li, low, mid)
        merge_sort(li, mid + 1, high)
        merge(li, low, mid, high)


li = list(range(5))
import random

random.shuffle(li)
print(li)
merge_sort(li, 0, 4)
